package br.com.mmsearch.hib;
// default package
// Generated 04/06/2013 00:03:37 by Hibernate Tools 4.0.0

import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;

import br.com.mmsearch.beans.Filme;

/**
 * Home object for domain model class Filme.
 * @see .Filme
 * @author Hibernate Tools
 */

public class FilmeHIB {

	public void salvar(Filme filme) {
		Session session = HibernateUtil.getSession();
		Transaction transaction = session.beginTransaction();
		session.saveOrUpdate(filme);
		transaction.commit();
		session.close();
	}

	public void excluir(Filme filme) {
		Session session = HibernateUtil.getSession();
		Transaction transaction = session.beginTransaction();
		session.delete(filme);
		transaction.commit();
		session.close();
		
	}
	
	public Filme consultar(int idFilme) {
		Session session = HibernateUtil.getSession();
		try {
			Filme obj = (Filme) session.get(Filme.class,idFilme);
			return obj;
		} finally {
			session.close();
		}
	}
	
	@SuppressWarnings("unchecked")
	public List<Filme> listar(){
		Session session = HibernateUtil.getSession();
		try{
			return session.createCriteria(Filme.class).list();
		}finally{
			session.close();
		}
	}
}
